package com.simple.piger.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.simple.piger.dto.req.InviteCompanyJobReqDto;
import com.simple.piger.enums.ApplyUserEduEnums;
import com.simple.piger.enums.CompanyJobStatusEnums;
import com.simple.piger.enums.InviteCompanyFinancingEnums;
import com.simple.piger.enums.InviteCompanyScaleEnums;
import com.simple.piger.utils.DateUtils;
import com.simple.piger.utils.IdUtil;
import com.simple.piger.utils.PageUtil;
import com.simple.piger.dto.resp.company.InviteCompanyJobRespDto;
import com.simple.piger.entity.InviteCompanyJob;
import com.simple.piger.mapper.InviteCompanyJobMapper;
import com.simple.piger.service.InviteCompanyJobService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baolw
 * @since 2020-02-06
 */
@Service
public class InviteCompanyJobServiceImpl extends ServiceImpl<InviteCompanyJobMapper, InviteCompanyJob> implements InviteCompanyJobService {

    @Override
    public List<InviteCompanyJobRespDto> list(Integer page, Integer limit, String name, String companyId) {
        List<InviteCompanyJobRespDto> list = this.baseMapper.list(PageUtil.getPageStart(page, limit), limit, name, companyId);
        for (InviteCompanyJobRespDto dto : list) {
            dto.setStatusName(CompanyJobStatusEnums.transfer(dto.getStatus()));
            dto.setEduRequireValue(ApplyUserEduEnums.transfer(dto.getEduRequire()));
            dto.setCreateDate(DateUtils.dateFormat(dto.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        return list;
    }

    @Override
    public int count(String name, String companyId) {
        return this.baseMapper.count(name, companyId);
    }

    @Override
    public List<InviteCompanyJobRespDto> homePageList(Integer page, Integer limit, String name) {
        List<InviteCompanyJobRespDto> list = this.baseMapper.homePageList(PageUtil.getPageStart(page, limit), limit, name);
        for (InviteCompanyJobRespDto dto : list) {
            dto.setStatusName(CompanyJobStatusEnums.transfer(dto.getStatus()));
            dto.setEduRequireValue(ApplyUserEduEnums.transfer(dto.getEduRequire()));
            dto.setCreateDate(DateUtils.dateFormat(dto.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        }
        return list;
    }

    @Override
    public int homePageListCount(String name) {
        return this.baseMapper.homePageListCount(name);
    }

    @Override
    public void saveOrUpdate(InviteCompanyJobReqDto reqDto) {
        if (StringUtils.isNotBlank(reqDto.getId())) {
            InviteCompanyJob job = this.selectById(reqDto.getId());
            job.setUpdateTime(new Date());
            job.setEduRequire(reqDto.getEduRequire());
            job.setJobAddress(reqDto.getJobAddress());
            job.setJobRequire(reqDto.getJobRequire());
            job.setJobDesc(reqDto.getJobDesc());
            job.setApplyUserId(reqDto.getApplyUserId());
            job.setJobTitle(reqDto.getJobTitle());
            job.setSalary(reqDto.getSalary());
            job.setStatus(reqDto.getStatus());
            job.setWorkAgeRequire(reqDto.getWorkAgeRequire());
            job.setJobWelfare(reqDto.getJobWelfare());
            job.updateById();
        } else {
            InviteCompanyJob job = new InviteCompanyJob();
            job.setId(IdUtil.getId());
            job.setCreateTime(new Date());
            job.setApplyUserId(reqDto.getApplyUserId());
            job.setUpdateTime(new Date());
            job.setEduRequire(reqDto.getEduRequire());
            job.setJobAddress(reqDto.getJobAddress());
            job.setJobRequire(reqDto.getJobRequire());
            job.setJobDesc(reqDto.getJobDesc());
            job.setJobTitle(reqDto.getJobTitle());
            job.setSalary(reqDto.getSalary());
            job.setStatus(reqDto.getStatus());
            job.setWorkAgeRequire(reqDto.getWorkAgeRequire());
            job.setJobWelfare(reqDto.getJobWelfare());
            job.setCompanyId(reqDto.getCompanyId());
            job.insert();
        }
    }
}
